package com.turato.table.processor;

import java.util.HashMap;
import java.util.Map;
import java.util.function.BiFunction;

/**
 * @author tuhao
 * @date 2021/2/5 11:16 下午
 * @desc
 */
public class FunctionProcessor {
    /**
     * 函数映射表
     */
    private HashMap<Integer , BiFunction<Integer,Integer,Integer>> map = new HashMap<>(16);

    public Map<Integer , BiFunction<Integer,Integer,Integer>> getFunctionMap() {
        return map;
    }

    public FunctionProcessor() {
        // 加法
        map.put(1, (x,y)->{
            System.out.println(x+y);
            return x+y;
        });
        // 减法
        map.put(2, (x,y)->{
            System.out.println(x-y);
            return x-y;
        });
        // 乘法
        map.put(3, (x,y)->{
            System.out.println(x*y);
            return x*y;
        });
        // 除法
        map.put(4, (x, y)-> {
            if (y.equals(0)) {
                throw new RuntimeException("/0错误");
            }
            System.out.println(x * 1.0 / y);
            return x/y;
        });
    }
}
